/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once
#include <iostream>

#pragma warning( disable : 4244)

#include "Image.h"

#include "../shared/Vector4f.h"
#include "../shared/Vector3f.h"
#include "../shared/vector.h"


class ICamera;
//class Image;

class Kernel;
// Window Event Callbacks
typedef void (Kernel::*OnCloseEventFuncPtr)();

/*-----------------------------------
    Video Property Flags
------------------------------------*/
enum Renderer_t {
    VF_IRRLICHT_DX8     = (1<<0),
    VF_IRRLICHT_DX9     = (1<<1),
    VF_IRRLICHT_OPENGL  = (1<<2),
    VF_IRRLICHT_SW      = (1<<3),
    VF_IRRLICHT_BV      = (1<<4)
};



/**
===============================================
Video Property Settings Write Access
===============================================
*/
struct ViewProperties
{
    int         width,          // width of the screen
                height,         // height
                frequency;      // monitor frequency

    bool        fullscreen;     // flag for fullscreen
    bool        vsync;          // vertical sync

    Renderer_t  type;           // Rendering Engine
    std::string windowTitle;    // Title of Window
    OnCloseEventFuncPtr closeEvent;     // window close event pointer
};

/**
===============================================
Video Property Settings Read only Access
===============================================
*/
const struct ViewSettings
{
    ViewSettings( ViewProperties p ) : m_properties(p) {};

    int  GetWidth()             const { return m_properties.width; };
    int  GetHeight()            const { return m_properties.height; };
    int  GetFreq()              const { return m_properties.frequency; };
    bool IsFullscreen()         const { return m_properties.fullscreen; };
    bool IsVsync()              const { return m_properties.vsync; };

    Renderer_t GetRenderer()    const { return m_properties.type; };
    std::string GetTitle()     const { return m_properties.windowTitle; };
    OnCloseEventFuncPtr GetWindowCloseEvent() const { return m_properties.closeEvent; };
private:
    ViewProperties  m_properties;
};

/**
===================================
Graphics Backend interface
===================================
*/
class IRender
{
public:
    /** Init the backend */
    virtual int Init(const ViewSettings &settings )=0;
    /** Clean up */
	virtual void Shutdown()=0;
    /** Get Renderer name */
    virtual Renderer_t GetName()=0;

    /** Set display name */
    virtual void SetTitle(const std::string &title )=0;
    /** Call a function on a window close event */
    virtual void OnCloseEvent( OnCloseEventFuncPtr func )=0;
    /** Draw an image */
	virtual void DrawImage( Image *im, int x, int y)=0;
    /** Draw an image at a set size, if repeat the the image repeats, else it stretchs */
    virtual void DrawImage( Image *im, int x, int y, float width, float height, bool repeat=true)=0;
    /** Draw an image which contains subimages */
    virtual void DrawSubImage( Image *im, int x, int y, int row, int col)=0;

    /** Draw a String */
    virtual void DrawString( int x, int y, const char *s,...)=0;
    /** Set a font type */
    virtual void SetFont( const std::string &font )=0;
    /** Draw an empty rect */
	virtual void DrawRect( int x, int y, int w, int h )=0;
    /** Draw a line */
    virtual void DrawLine( const Vector3f &p1, const Vector3f &p2 )=0;
	/** Fill in a rect */
    virtual void FillRect( int x, int y, int w, int h )=0;
    /** Fill in a rotated rect */
	virtual void FillRectRotate(int x, int y, int w, int h, double rotation)=0;

    /** Draw an empty circle */
    virtual void DrawCircle( float radius, int x, int y)=0;
    /** Fill in a circle */
    virtual void FillCircle( float radius, int x, int y)=0;
    /** get a chars height */
    virtual int GetTextHeight(char)=0;
    /** Get a chars width */
    virtual int GetTextWidth(char)=0;

    /** Set the current Vector4f */
	virtual void  SetColor( float r, float g, float b, float a=1)=0;
    virtual void  SetColor(Vector4f c)=0;
    /** Get the current Vector4f */
    virtual Vector4f GetColor()=0;
    /** Apply a Color effect */
	virtual void  SetColorEffect( float r, float g, float b, float a=1)=0;
    virtual void  SetColorEffect(Vector4f c)=0;
    /** Get the Vector4f effect Vector4f */
    virtual Vector4f GetColorEffect()=0;
    /** Setup for this frames render */
	virtual void PreRender()=0;
    /** Clean up */
	virtual void PostRender()=0;

    /** Enable fog */
    virtual void EnableFog()=0;
    /** Disable fog */
    virtual void DisableFog()=0;
    /** Set the fog density */
    virtual void SetFogDensity(float density)=0;
    /** Set the fog Vector4f */
    virtual void ChangeFogColor(float r, float g, float b, float a=1)=0;
    virtual void ChangeFogColor(Vector4f)=0;
    /** Get the fog Vector4f */
    virtual Vector4f GetFogColor()=0;

    /*----------------------------------------------------
        Camera
    ----------------------------------------------------*/
    //virtual ICamera* GetCamera()=0;
    //virtual void SetCamera( ICamera* c )=0;
    
};

